﻿BEGIN TRY
	BEGIN TRAN

	MERGE [dbo].[Language] AS TGT 
	USING
	(
		SELECT 1, 'Microsoft SQL Server T-SQL' UNION ALL
		SELECT 2, 'Microsoft Azure SQL Data Warehouse T-SQL'
	) AS SRC ([LanguageId], [LanguageName])
	ON TGT.[LanguageId] = SRC.[LanguageId]  

	WHEN MATCHED THEN   
	UPDATE SET
		[LanguageName] = SRC.[LanguageName]
	WHEN NOT MATCHED BY TARGET THEN  
		INSERT ([LanguageId], [LanguageName])
		VALUES (SRC.[LanguageId], SRC.[LanguageName])

	WHEN NOT MATCHED BY SOURCE THEN  
		DELETE;

	COMMIT TRAN;
END TRY
BEGIN CATCH
	ROLLBACK TRAN;
END CATCH
